import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_audioplayers.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_photo.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_video.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_button_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/common/simple_choice_bean.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/responsibility/task_list/responsibility_task_details/responsibility_task_details_controller.dart';

/// 包保责任任务详情页面
class ResponsibilityTaskDetailsPage extends StatelessWidget {
  ResponsibilityTaskDetailsPage({super.key});

  final controller = Get.put(ResponsibilityTaskDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        if (controller.detailEntity == null) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '任务履职',
            ),
          );
        }
        return Scaffold(
          appBar: CustomAppBar(
            titleText: '任务履职',
          ),
          body: Container(
            alignment: Alignment.center,
            color: const Color(0xffF5F5F6),
            child: Column(
              children: [
                AppGaps.vGap16,
                Expanded(
                    child: Container(
                  color: Colors.white,
                  child: SingleChildScrollView(
                    child: _getContentView(),
                  ),
                )),
              ],
            ),
          ),
          bottomSheet: Visibility(
            visible: controller.isEnabled,
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
              decoration: BoxDecoration(
                color: Colors.white,
                boxShadow: [
                  BoxShadow(
                    color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
                    offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
                    blurRadius: 10.0, // 阴影的模糊半径
                    spreadRadius: 2.0, // 阴影的扩散半径
                  ),
                ],
              ),
              child: Row(
                children: [
                  Container(
                      height: 40.w,
                      width: 120.w,
                      margin: EdgeInsets.only(right: 20.w),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: const Color(0xffffffff),
                          border: Border.all(color: const Color(0xff5C6DFF), width: 1.w),
                          borderRadius: BorderRadius.all(Radius.circular(20.w))),
                      child: Text(
                        '取消',
                        style: TextStyle(
                          fontSize: 16.sp,
                          color: const Color(0xff5C6DFF),
                        ),
                      )).clickOnce(controller.cancelTap),
                  Expanded(
                    child: Container(
                        height: 40.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(color: const Color(0xff5C6DFF), borderRadius: BorderRadius.all(Radius.circular(20.w))),
                        child: Text(
                          '提交',
                          style: TextStyle(
                            fontSize: 16.sp,
                            color: const Color(0xffffffff),
                          ),
                        )).clickOnce(controller.submitTap),
                  ),
                ],
              ),
            ),
          ),
        );
      },
    );
  }

  /// 填写输入内容
  Widget _getContentView() {
    return Column(
      children: [
        Container(
          padding: EdgeInsets.symmetric(vertical: 14.w, horizontal: 16.w),
          child: Row(
            children: [
              Container(
                  width: 16.w,
                  height: 16.w,
                  decoration: BoxDecoration(
                      color: const Color(0xff5C6DFF),
                      border: Border.all(color: const Color(0xffEEF0FF), width: 4.w),
                      borderRadius: BorderRadius.all(Radius.circular(90.r)))),
              AppGaps.hGap8,
              Expanded(
                child: Text(
                  controller.taskName,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: const Color(0xff333333),
                  ),
                ),
              ),
            ],
          ),
        ),
        Divider(
          height: 1.w,
          color: const Color(0xffDEE5FD),
        ),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 16.w),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Text(
                    '排查结果：',
                    style: TextStyle(fontSize: 14.sp, height: 1.2, color: const Color(0xFF262F38), fontWeight: FontWeight.w400),
                  ),
                  Expanded(
                    child: CustomSelectButtonPage<SimpleChoiceBean>(
                      isEnabled: controller.isEnabled,
                      wrapAlignment: WrapAlignment.end,
                      dataList: controller.choiceDataList,
                      onConfirm: (List<SimpleChoiceBean> value) {
                        if (value.isNotEmpty) {
                          if (value[0].id == '1') {
                            controller.isNormal = true;
                          } else {
                            controller.isNormal = false;
                          }
                        }
                        controller.update();
                      },
                    ),
                  )
                ],
              ),
              Divider(
                height: 1.w,
                color: const Color(0xffECEEF3),
              ),
              CustomHighInputPage(
                title: '巡检描述：',
                isRequired: false,
                text: controller.detailEntity!.inspectionDescription,
                isEnabled: controller.isEnabled,
                hintText: '请输入意见',
                onCallBack: (value) {
                  controller.detailEntity!.inspectionDescription = value;
                },
              ),
              CustomPickerPhoto(
                title: '拍照:',
                maxCount: 9,
                imagesList: controller.detailEntity!.inspectionPhotos!,
                isEnabled: controller.isEnabled,
                titleTextStyle: TextStyle(
                  fontSize: 14.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w500,
                  color: const Color(0xff262F38),
                ),
              ),
              Divider(
                height: 1.w,
                color: const Color(0xffECEEF3),
              ),
              CustomPickerVideo(
                title: '拍摄:',
                maxCount: 9,
                isEnabled: controller.isEnabled,
                videoList: controller.detailEntity!.inspectionVideos!,
                titleTextStyle: TextStyle(
                  fontSize: 14.sp,
                  height: 1.2,
                  fontWeight: FontWeight.w500,
                  color: const Color(0xff262F38),
                ),
              ),
              Divider(
                height: 1.w,
                color: const Color(0xffECEEF3),
              ),
              AppGaps.vGap20,
              Text(
                '语音:',
                style: TextStyle(fontSize: 14.sp, height: 1.2, color: const Color(0xFF262F38), fontWeight: FontWeight.w400),
              ),
              AppGaps.vGap16,
              Visibility(
                visible: controller.isEnabled,
                child: Column(
                  children: [
                    SvgPicture.asset(
                      AppImages.icon_tape,
                      width: 80.w,
                      height: 80.w,
                    ).clickOnce(controller.onTapTape),
                    AppGaps.vGap16,
                  ],
                ),
              ),
              CustomAudioplayers(
                isEnabled: controller.isEnabled,
                audioUrl: controller.detailEntity!.patrolVoices!,
                key: controller.globalKey,
                onCallBack: (List<String> urls) {
                  controller.detailEntity!.patrolVoices!.clear();
                  controller.detailEntity!.patrolVoices!.addAll(urls);
                  controller.update();
                },
              ),
            ],
          ),
        ),
        SizedBox(height: 70.w)
      ],
    );
  }
}
